package com.train.dao;

import com.train.pojo.Movie;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class DaoMovie {
    public List getCount(){
        List list=null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url="jdbc:mysql://localhost:3306/train";
            Connection conn= DriverManager.getConnection(url,"root","20031011LK");
            String sql="select country,count from movie_lang_count order by count desc";
            PreparedStatement ps= conn.prepareStatement(sql);
            ResultSet rs=ps.executeQuery();
            list=new ArrayList<>();
            while(rs.next()){
                String name = rs.getString("country");
                int value = rs.getInt("count");
                Movie movie = new Movie(name,value);
                list.add(movie);
            }
            rs.close();
            ps.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

}
